home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Applications / Nuntius 1.2 / src / MyToolSource / IsModifierKeyDown.cp < prev    next >
Encoding:
Text File  |  1992-12-27  |  1.5 KB  |  78 lines  |  [TEXT/MPS ]

  1. #include <stream.h>
  2. #include <Types.h>
  3. #include <Events.h>
  4. #include <stdlib.h>
  5.  
  6. Boolean IsThisKeyDown(const short theKey)
  7. {
  8.     union
  9.     {
  10.         KeyMap asMap;
  11.         Byte asBytes[16];
  12.     };
  13.  
  14.     GetKeys(asMap);
  15.     return asBytes[theKey >> 3] & (1 << (theKey & 0x07)) ? true : false;
  16. } // IsThisKeyDown 
  17.  
  18. pascal Boolean IsCommandKeyDown()
  19. {
  20.     const short kCommandKey = 55;
  21.     return IsThisKeyDown(kCommandKey);
  22. } // IsCommandKeyDown 
  23.  
  24. pascal Boolean IsControlKeyDown()
  25. {
  26.     const short kCtlKey = 0x3B;
  27.     return IsThisKeyDown(kCtlKey);
  28. } // IsControlKeyDown 
  29.  
  30. pascal Boolean IsOptionKeyDown()
  31. {
  32.     const short kOptionKey = 58;
  33.     return IsThisKeyDown(kOptionKey);
  34. } // IsOptionKeyDown 
  35.  
  36. pascal Boolean IsShiftKeyDown()
  37. {
  38.     const short kShiftKey = 56;
  39.     return IsThisKeyDown(kShiftKey);
  40. } // IsShiftKeyDown 
  41.  
  42.  
  43. void PrintUsage()
  44. {
  45.     cerr << "### IsModifierKeyDown - bad or missing parameter\n";
  46.     cerr << "# Usage - IsModifierKeyDown [-option] [-shift] [-control] [-command]\n";
  47.     exit(1);
  48. }
  49.  
  50. Boolean gIsGood = true;
  51.  
  52. void CheckKey(Boolean down)
  53. {
  54.     if (!down)
  55.         gIsGood = false;
  56. }
  57.  
  58. int main(int argc,char *argv[])
  59. {
  60.     while ((--argc != 0) && (*++argv)[0] == '-') 
  61.     {
  62.         const char *p = argv[0];
  63.         if (strcmp(p, "-option") == 0)
  64.             CheckKey(IsOptionKeyDown());
  65.         else if (strcmp(p, "-shift") == 0)
  66.             CheckKey(IsShiftKeyDown());
  67.         else if (strcmp(p, "-control") == 0)
  68.             CheckKey(IsControlKeyDown());
  69.         else if (strcmp(p, "-command") == 0)
  70.             CheckKey(IsCommandKeyDown());
  71.         else
  72.             PrintUsage();
  73.     }
  74.     if (argc != 0)
  75.         PrintUsage();
  76.     cout << (gIsGood ? "1" : "0");
  77.     return 0;
  78. }